/*servertest.c*/
/*assume that the server is machine 0*/
#include "syscall.h"
#include "syscall2.h"

int myMVs[1024];

int main()
{	
	int i = 0;
	int r=0;
	int c=0;
	int test=0;
	int outputLen = 0;
	char outBuff[32];

Write("MV Tests Beginning...\n",22,ConsoleOutput);
	/*create 500 MVs*/
	for(i = 0; i < 25; i++)
	{
		myMVs[i] = CreateMV(11,11);
		ConsoleAcquire();
			Write("Created MV ",11,ConsoleOutput);
			outputLen = Itoa(myMVs[i], outBuff);
			Write(outBuff , outputLen, ConsoleOutput);
			Write("\n",1,ConsoleOutput);
		ConsoleRelease();
	}
	
	/*set values for every spot*/
	for(i = 0; i < 25; i++)
	{
		for(r = 0; r < 5; r++)
		{
			for(c = 0; c < 5; c++)
			{
				SetMV(myMVs[i],r,c, (r*32)+c);
			}
		}
	}
	
	/* test that all the values are correct */
	for(i = 0; i < 25; i++)
	{
		for(r = 0; r < 5; r++)
		{
			for(c = 0; c < 5; c++)
			{
				test = GetMV(myMVs[i],r,c);
				if(test != ((r*32)+c))
				{
					ConsoleAcquire();
						Write("Value test failed!\n",19,ConsoleOutput);
						Write("Expected value: ",16,ConsoleOutput);
						outputLen = Itoa((r*32)+c, outBuff);
						Write(outBuff , outputLen, ConsoleOutput);
						Write("\n",1,ConsoleOutput);
						Write("Returned value: ",16,ConsoleOutput);
						outputLen = Itoa(test, outBuff);
						Write(outBuff , outputLen, ConsoleOutput);
						Write("\n",1,ConsoleOutput);
					ConsoleRelease();
					Halt();
				}
			}
		}
	}
	
	ConsoleAcquire();
		Write("Server test complete!\n",22,ConsoleOutput);
	ConsoleRelease();
	Exit(0);
}